package com.clkj.xiuzheng.controller.shangcheng;

import com.clkj.xiuzheng.dao.shangcheng.ScBrandMapper;
import com.clkj.xiuzheng.pojo.common.Result;
import com.clkj.xiuzheng.pojo.common.StatusCode;
import com.clkj.xiuzheng.pojo.shangcheng.ProductBrand;
import com.clkj.xiuzheng.service.shangcheng.ScBrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/ScBrand")
@CrossOrigin
@Api(value = "/ScBrand", tags = {"Z商城品牌管理"})
public class ScBrandController {

    @Autowired
    private ScBrandService scBrandService;

    @ApiOperation(value = "添加品牌商")
    @PostMapping("/addBrand")
    public Result addBrand(@RequestBody ProductBrand productBrand) {
        try {
            scBrandService.addBrand(productBrand);
            return new Result(true, StatusCode.OK,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"修改失败");
        }
    }
    @ApiOperation(value = "获取品牌商")
    @PostMapping("/getBrandList")
    public Result getBrandList(@ApiParam(name = "brandName", value = "品牌商名称")@RequestParam(required = false) String brandName, @ApiParam(name = "companyId", value = "公司ID")@RequestParam(required = false) Integer companyId) {
        try {
         List<ProductBrand> list =   scBrandService.getBrandList(brandName,companyId);
            return new Result(true, StatusCode.OK,"修改成功",list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"修改失败");
        }
    }

    @ApiOperation(value = "修改品牌商状态")
    @PostMapping("/updateBrandStatus")
        public Result updateBrandStatus(@ApiParam(name = "Ids", value = "品牌商id集合字符串用,分割") @RequestParam("Ids") String Ids,
                                    @ApiParam(name = "status", value = "0下架 1上架") @RequestParam("status") Integer status) {
        try {
            scBrandService.updateBrandStatus(Ids,status);
            return new Result(true, StatusCode.OK,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"修改失败");
        }
    }
    @ApiOperation(value = "修改品牌商名字")
    @PostMapping("/updateBrandName")
    public Result updateBrandName(@ApiParam(name = "brandId", value = "品牌商id") @RequestParam("brandId") Integer brandId,
                                  @ApiParam(name = "brandName", value = "品牌商名字") @RequestParam("brandName") String brandName) {
        try {
            scBrandService.updateBrandName(brandId,brandName);
            return new Result(true, StatusCode.OK,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
           return new Result(false, StatusCode.ERROR,"修改失败");
       }
   }

}